using Rokid.UXR.Module;
using UnityEngine;
using UnityEngine.Assertions;

/// <summary>
///
/// make 4 GameObjects to the tracked image's corners
/// make an overly plane over the tracked image
/// </summary>
public class TrackImageDemo : MonoBehaviour
{
    
    [SerializeField] private GameObject prefab;
    
    private bool isInitialize;
    
    // Start is called before the first frame update
    void Start()
    {
        Assert.IsNotNull(prefab);
        if (isInitialize) return;
        
        //set all inactive when setup
        isInitialize = true;
        prefab.SetActive(false);
    }

    public void OnTrackedImageAdded(ARTrackedImageObj imageObj)
    {
        isInitialize = true;

        prefab.SetActive(true);
        
        //set as same when update
        OnTrackedImageUpdate(imageObj);
    }
    
    public void OnTrackedImageUpdate(ARTrackedImageObj imageObj)
    {
       
        prefab.transform.position = imageObj.trackedImage.pose.position;
        prefab.transform.rotation = imageObj.trackedImage.pose.rotation;
    }
    
    public void OnTrackedImageRemoved(ARTrackedImageObj trackedImage)
    {
        isInitialize = false;
        prefab.SetActive(false);
    }
}